var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Tests = require('../models/tests')

mongoose.connect('mongodb://127.0.0.1:27017/test');

mongoose.connection.on('connected',function(){
	console.log('success')
})

mongoose.connection.on('error',function(){
	console.log('error')
})

mongoose.connection.on('disconnected',function(){
	console.log('disconnected')
})
/* GET users listing. */
router.get('/', function(req, res, next) {
	Tests.find({},{title:1},function(err,doc){
		if(err){
			res.json({
				status:"1",
				msg:err.message
			})
		}else{
			res.json({
				status:'0',
				msg:"",
				result:{
					count:doc.length,
					list:doc
				}
			})
		}
	})
});

module.exports = router;
